$(function () {
   obj.init();
});
var obj = new function () {
    'use strict';
    return {
        form:null,
        dataGrid:null,
        init:function () {
            this.dataGrid = new xhDataGrid($('#recList'),'hrm/attendance/getRecord');
            this.dataGrid.parseToolbar().init();
            this.listener();
        },
        listener:function () {
            var $this = this;
            //导入
            // $('#bt_list_importRec').click(function () {
            //     $this.funObj().importRecord();
            // });
            //生成
            $('#bt_list_generate').click(function () {
                $this.funObj().generateForm();
            });

            //搜索
            $('#bt_list_search').click(function () {
                $this.funObj().doSearch();
            });
            xhTool.bindDocKeyDown($('#bt_list_search'));
        },
        funObj:function () {
            var $this = this;
            return {
                importRecord:function () {
                    window.top.swal({
                        title: '导入excel文件',
                        showCancelButton: true,
                        cancelButtonText: '取消',
                        showLoaderOnConfirm: true,
                        allowOutsideClick: true,
                        input: 'file',
                        inputAttributes: {accept: '.xls,.xlsx'},
                        confirmButtonText: '导入',
                        preConfirm: function(file) {
                            return new Promise(function (resolve, reject) {
                                if (!file) {
                                    reject('文件不能为空！');
                                } else {
                                    var fileData = new FormData();
                                    fileData.append('file', file);
                                    $.ajax({
                                        url: baseUrl + 'hrm/attendance/importAttend',
                                        type: 'POST',
                                        processData: false,
                                        contentType: false,
                                        data: fileData,
                                        complete: function(XMLHttpRequest){
                                            var result = XMLHttpRequest.responseJSON;
                                            if(xhExtra.checkError(result)) return false;
                                             window.top.xhTop.showSuccess(result.msg);
                                            $this.dataGrid.reload();
                                        }
                                    });
                                }
                            })
                        }
                    });
                },
                doSearch:function () {
                    $this.dataGrid.reload({
                        key: xhExtra.getValue($('#list_search')),
                        startTime:xhExtra.getValue($('#List_Search_StartTime')),
                        endTime:xhExtra.getValue($('#List_Search_EndTime'))
                    })
                },
                generateForm:function () {
                    window.top.xhTop.showModal({
                        title: '生成每日考勤',
                        content: '<iframe src="'+moduleUrl+'attendance/generateForm"  style="width: 100%;;border-style: none;padding: 0px;"  scrolling="yes"   ></iframe>',
                        button:'提交',
                        backClose: false
                    });
                }
            }
        }
    }
};